<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
</head>

<body>
    <div class="nav">
        <img src="image/image1.jpg" alt="">
        <span class="title">我的博客系统</span>
        <span class="spacer"></span>
        <a href="register.html">注册 </a>
    </div>

    <div class="login-container">
        <div class="login-dialog">
            <h3>登录</h3>
            <div class="row">
                <span>用户名</span>
                <input type="text" id="username" name="username">
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" id="password" name="password">
            </div>
            <div class="row submit-row">
                <button id="submit" onclick="login()">登录</button>
            </div>
        </div>
    </div>
</body>
<script src="js/jquery.min.js"></script>
<script>
    function login() {
        var username = jQuery("#username");
        var password = jQuery("#password");
        if (jQuery.trim(username.val()) == "") {
            alert("请先输入登录名！");
            username.focus();
            return;
        }
        if (jQuery.trim(password.val()) == "") {
            alert("请先输入密码！");
            password.focus();
            return;
        }
        jQuery.ajax({
            url: "user/login",
            tyep: "POST",
            data: {
                "username": username.val(),
                "password": password.val()
            },
            success: function (result) {
                if (result != null && result.success == 200) {
                    if (result.data == 1) {
                        location.href ="blog_list.html";
                    } else {
                        alert("用户名或密码错误，请重新插入！");
                    }
                } else {
                    alert("后端程序不可用");
                }
            }
        });
    }
</script>

</html>